package com.example.netty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @Date 2022/10/27
 * @Author Jonathan
 * 异步化的工作 考虑使用future  最后把处理结果返回给调用线程
 */
public class TestJDKFuture {

    private static final Logger log = LoggerFactory.getLogger(TestJDKFuture.class);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(2);
        Future<Integer> future = service.submit(() -> {
            TimeUnit.SECONDS.sleep(1);
            log.info("-_-");
            return 1;
        });
        log.info("ret is:{}", future.get());
    }
}
